/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * OturumIslemleri.java
 *
 * Created on 27.Ara.2011, 11:57:12
 */
package oopdesignpatternsproject;

import entityclasses.Session;
import java.awt.Component;
import javax.swing.ComboBoxModel;
import javax.swing.JLabel;
import javax.swing.JPanel;
import entityclasses.PlainTextShare;
import entityclasses.Share;
import entityclasses.Person;
import entityclasses.SocialApp;

/**
 *
 * @author umutcan
 */
public class OturumIslemleri extends javax.swing.JFrame {
    JLabel lblKullaniciAdi;
    JLabel lblProfilAdi;
    JPanel pnlPaylasimlar;
    /** Creates new form OturumIslemleri */
    public OturumIslemleri(JLabel lblKullaniciAdi, JLabel lblProfilAdi, JPanel pnlPaylasimlar) {
        initComponents();
        
        this.lblKullaniciAdi = lblKullaniciAdi;
        this.lblProfilAdi = lblProfilAdi;
        this.pnlPaylasimlar = pnlPaylasimlar;
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        
        for (Person p : SocialApp.instance().getRegisteredPersons())
            cmbKullanicilar.addItem(p);
        
        
        
        
        
        
    }
        public OturumIslemleri() {
        initComponents();
        
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        
        
        
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        cmbKullanicilar = new javax.swing.JComboBox();
        btnOturumAc = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Oturum Açacak Kullanıcı");
        jLabel1.setName("jLabel1"); // NOI18N

        cmbKullanicilar.setName("cmbKullanicilar"); // NOI18N

        btnOturumAc.setText("Oturum Aç");
        btnOturumAc.setName("btnOturumAc"); // NOI18N
        btnOturumAc.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnOturumAcMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(cmbKullanicilar, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(btnOturumAc))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(23, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmbKullanicilar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnOturumAc)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnOturumAcMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnOturumAcMouseClicked
        ComboBoxModel cmbModel  =  cmbKullanicilar.getModel();
        
        Session.currentUser = (Person)cmbModel.getSelectedItem();
        lblKullaniciAdi.setText(Session.currentUser.getFirstName() + " "+ Session.currentUser.getLastName());
        lblProfilAdi.setText(Session.currentUser.getProfile().getProfileName());
        pnlPaylasimlar.removeAll();
        for (Share s : Session.currentUser.getProfile().getShares()) {
            JLabel paylasim = new JLabel();
            if (s.getShareStrategy() instanceof PlainTextShare) {
                paylasim.setText(s.getContent());
            } else {
                paylasim.setText("<html><font color=\"#0000CF\"><u>" + s.getContent() + "</u></font></html>");
            }
            paylasim.setSize(600, 50);
            paylasim.setVisible(true);
            int sayac = 0;
            for (Component c : pnlPaylasimlar.getComponents()) {
                sayac += 50;
                c.setLocation(c.WIDTH, c.HEIGHT + sayac);
            }
            pnlPaylasimlar.add(paylasim);
        }
    }//GEN-LAST:event_btnOturumAcMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(OturumIslemleri.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(OturumIslemleri.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(OturumIslemleri.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(OturumIslemleri.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new OturumIslemleri().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnOturumAc;
    private javax.swing.JComboBox cmbKullanicilar;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables
}
